home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Collection of Tools & Utilities
/
Collection of Tools and Utilities.iso
/
dirut
/
rm_om.zip
/
ASKREPLY.C
< prev
next >
Wrap
C/C++ Source or Header
|
1991-10-16
|
993b
|
61 lines
/*
** Ask the user for a yes/no/quit/all answer, depending on default
*/
#include <stdio.h>
#include <sgtty.h>
#include "ascii.h"
#include "askreply.h"
int askreply(assume)
int assume; {
redo: switch(readchar()) {
case 'y':
case 'Y':
yes: printf("Yes\n");
return YES;
case 'n':
case 'N':
no: printf("No\n");
return NO;
case 'x':
case 'X':
case 'q':
case 'Q':
case SUB:
case ESC:
case EOF:
quit: printf("Quit\n");
return QUIT;
case 'a':
case 'A':
all: printf("All\n");
return ALL;
default:
if(assume==YES) goto yes;
if(assume==NO) goto no;
if(assume==QUIT) goto quit;
if(assume==ALL) goto all;
putchar('\7');
goto redo;
}
}
int readchar() {
if(isatty(fileno(stdin))) {
register int c;
struct sgttyb arg;
ioctl(1,TIOCGETP,&arg);
arg.sg_flags|=RAW;
ioctl(1,TIOCSETP,&arg);
c=getc(stdin);
arg.sg_flags^=RAW;
ioctl(1,TIOCSETP,&arg);
return(c);
}
return agetc(stdin);
}